Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Django execute_code command #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

janfabry
Copy link
Contributor

Pipe Python code via heredoc to Django shell. Crude, but it works. --plain always uses the regular Python instead of IPython, this gives us consistency over all servers.

Pipe Python code via heredoc to Django shell
@@ -147,6 +147,8 @@ def settings_module(self):
def wsgi_app_location(self):
return '/etc/wsgi-apps/%s.py' % self.slug

def execute_code(self, code):
self.hosts.run(self._get_management_command('shell --plain') + " <<__HEREDOC__\n" + code + "\n__HEREDOC__")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on magic escape characters and can possibly suffer from injection.

Please refactor to something like this:

self.hosts.run(self._get_management_command('shell --plain'), initial_input = '%s\nimport sys; sys.exit(0)' % code)

That should already work out of the box.

Better would even be, to add a boolean option to Host._run and Host._posix_shell called "send_EOF_after_initial_input"
If True, send Ctrl-D after the initial input.

Then it becomes:

self.hosts.run(self._get_management_command('shell --plain'), initial_input=code, send_EOF_after_initial_input=True)

Not sure about the naming, but that's the idea.

@jonathanslenders jonathanslenders force-pushed the master branch 2 times, most recently from cf54f50 to 32c1030 Compare October 21, 2014 08:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants